<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>perlreref - Perl Regular Expressions Reference - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/perlreref">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlreref.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/perlreref">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/perlreref">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/perlreref">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/perlreref">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/perlreref">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/perlreref">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/perlreref">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/perlreref">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/perlreref">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/perlreref">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/perlreref">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/perlreref">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/perlreref">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/perlreref">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/perlreref">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/perlreref">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/perlreref">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/perlreref">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/perlreref">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/perlreref">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/perlreref">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/perlreref">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/perlreref">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/perlreref">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/perlreref">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/perlreref">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/perlreref">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/perlreref">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/perlreref">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/perlreref">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/perlreref">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/perlreref">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/perlreref">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/perlreref">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/perlreref">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/perlreref">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/perlreref">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/perlreref">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/perlreref">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/perlreref">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/perlreref">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/perlreref">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/perlreref">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/perlreref">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/perlreref">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/perlreref">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/perlreref">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/perlreref">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/perlreref">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/perlreref">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/perlreref">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/perlreref">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/perlreref">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/perlreref">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/perlreref">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/perlreref">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/perlreref">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/perlreref">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/perlreref">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/perlreref">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/perlreref">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/perlreref">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/perlreref">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/perlreref">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/perlreref">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/perlreref">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/perlreref">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/perlreref">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/perlreref">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/perlreref">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/perlreref">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/perlreref">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/perlreref">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/perlreref">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/perlreref">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/perlreref">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/perlreref">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/perlreref">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/perlreref">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/perlreref">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlreref.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/perlreref">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/perlreref">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/perlreref">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/perlreref">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/perlreref">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/perlreref">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/perlreref">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/perlreref">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/perlreref">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/perlreref">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/perlreref">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/perlreref">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/perlreref">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/perlreref">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/perlreref">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/perlreref">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/perlreref">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/perlreref">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/perlreref">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/perlreref">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/perlreref">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/perlreref">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/perlreref">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/perlreref">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/perlreref">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/perlreref">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/perlreref">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/perlreref">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/perlreref">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/perlreref">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/perlreref">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/perlreref">5.35.1</a>
          <a class="dropdown-item active" href="perlreref.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlreref.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="perlreref.html">perlreref</a>
          <div id="more">
            (<a href="perlreref.txt">source</a>,
            <a href="https://metacpan.org/pod/perlreref">CPAN</a>)
          </div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="perlreref.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#DESCRIPTION">DESCRIPTION</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlreref.html#OPERATORS">OPERATORS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#SYNTAX">SYNTAX</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#ESCAPE-SEQUENCES">ESCAPE SEQUENCES</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#CHARACTER-CLASSES">CHARACTER CLASSES</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#ANCHORS">ANCHORS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#QUANTIFIERS">QUANTIFIERS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#EXTENDED-CONSTRUCTS">EXTENDED CONSTRUCTS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#VARIABLES">VARIABLES</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#FUNCTIONS">FUNCTIONS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#TERMINOLOGY">TERMINOLOGY</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlreref.html#Titlecase">Titlecase</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#Foldcase">Foldcase</a>
              </li>
          </ul>

              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#AUTHOR">AUTHOR</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#SEE-ALSO">SEE ALSO</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreref.html#THANKS">THANKS</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="perlreref.html#NAME">#</a>NAME</h1>

<p>perlreref - Perl Regular Expressions Reference</p>

<h1 id="DESCRIPTION"><a class="permalink" href="perlreref.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>This is a quick reference to Perl&#39;s regular expressions. For full information see <a href="perlre.html">perlre</a> and <a href="perlop.html">perlop</a>, as well as the <a href="perlreref.html#SEE-ALSO">&quot;SEE ALSO&quot;</a> section in this document.</p>

<h2 id="OPERATORS"><a class="permalink" href="perlreref.html#OPERATORS">#</a>OPERATORS</h2>

<p><code>=~</code> determines to which variable the regex is applied. In its absence, $_ is used.</p>

<pre><code>$var =~ /foo/;</code></pre>

<p><code>!~</code> determines to which variable the regex is applied, and negates the result of the match; it returns false if the match succeeds, and true if it fails.</p>

<pre><code>$var !~ /foo/;</code></pre>

<p><code>m/pattern/msixpogcdualn</code> searches a string for a pattern match, applying the given options.</p>

<pre><code>m  Multiline mode - ^ and $ match internal lines
s  match as a Single line - . matches \n
i  case-Insensitive
x  eXtended legibility - free whitespace and comments
p  Preserve a copy of the matched string -
   ${^PREMATCH}, ${^MATCH}, ${^POSTMATCH} will be defined.
o  compile pattern Once
g  Global - all occurrences
c  don&#39;t reset pos on failed matches when using /g
a  restrict \d, \s, \w and [:posix:] to match ASCII only
aa (two a&#39;s) also /i matches exclude ASCII/non-ASCII
l  match according to current locale
u  match according to Unicode rules
d  match according to native rules unless something indicates
   Unicode
n  Non-capture mode. Don&#39;t let () fill in $1, $2, etc...</code></pre>

<p>If &#39;pattern&#39; is an empty string, the last <i>successfully</i> matched regex is used. Delimiters other than &#39;/&#39; may be used for both this operator and the following ones. The leading <code>m</code> can be omitted if the delimiter is &#39;/&#39;.</p>

<p><code>qr/pattern/msixpodualn</code> lets you store a regex in a variable, or pass one around. Modifiers as for <code>m//</code>, and are stored within the regex.</p>

<p><code>s/pattern/replacement/msixpogcedual</code> substitutes matches of &#39;pattern&#39; with &#39;replacement&#39;. Modifiers as for <code>m//</code>, with two additions:</p>

<pre><code class="plaintext">e  Evaluate &#39;replacement&#39; as an expression
r  Return substitution and leave the original string untouched.</code></pre>

<p>&#39;e&#39; may be specified multiple times. &#39;replacement&#39; is interpreted as a double quoted string unless a single-quote (<code>&#39;</code>) is the delimiter.</p>

<p><code>m?pattern?</code> is like <code>m/pattern/</code> but matches only once. No alternate delimiters can be used. Must be reset with reset().</p>

<h2 id="SYNTAX"><a class="permalink" href="perlreref.html#SYNTAX">#</a>SYNTAX</h2>

<pre><code>\       Escapes the character immediately following it
.       Matches any single character except a newline (unless /s is
          used)
^       Matches at the beginning of the string (or line, if /m is used)
$       Matches at the end of the string (or line, if /m is used)
*       Matches the preceding element 0 or more times
+       Matches the preceding element 1 or more times
?       Matches the preceding element 0 or 1 times
{...}   Specifies a range of occurrences for the element preceding it
[...]   Matches any one of the characters contained within the brackets
(...)   Groups subexpressions for capturing to $1, $2...
(?:...) Groups subexpressions without capturing (cluster)
|       Matches either the subexpression preceding or following it
\g1 or \g{1}, \g2 ...    Matches the text from the Nth group
\1, \2, \3 ...           Matches the text from the Nth group
\g-1 or \g{-1}, \g-2 ... Matches the text from the Nth previous group
\g{name}     Named backreference
\k&lt;name&gt;     Named backreference
\k&#39;name&#39;     Named backreference
(?P=name)    Named backreference (python syntax)</code></pre>

<h2 id="ESCAPE-SEQUENCES"><a class="permalink" href="perlreref.html#ESCAPE-SEQUENCES">#</a><a id="ESCAPE"></a>ESCAPE SEQUENCES</h2>

<p>These work as in normal strings.</p>

<pre><code class="plaintext">\a       Alarm (beep)
\e       Escape
\f       Formfeed
\n       Newline
\r       Carriage return
\t       Tab
\037     Char whose ordinal is the 3 octal digits, max \777
\o{2307} Char whose ordinal is the octal number, unrestricted
\x7f     Char whose ordinal is the 2 hex digits, max \xFF
\x{263a} Char whose ordinal is the hex number, unrestricted
\cx      Control-x
\N{name} A named Unicode character or character sequence
\N{U+263D} A Unicode character by hex ordinal

\l  Lowercase next character
\u  Titlecase next character
\L  Lowercase until \E
\U  Uppercase until \E
\F  Foldcase until \E
\Q  Disable pattern metacharacters until \E
\E  End modification</code></pre>

<p>For Titlecase, see <a href="perlreref.html#Titlecase">&quot;Titlecase&quot;</a>.</p>

<p>This one works differently from normal strings:</p>

<pre><code class="plaintext">\b  An assertion, not backspace, except in a character class</code></pre>

<h2 id="CHARACTER-CLASSES"><a class="permalink" href="perlreref.html#CHARACTER-CLASSES">#</a><a id="CHARACTER"></a>CHARACTER CLASSES</h2>

<pre><code class="plaintext">[amy]    Match &#39;a&#39;, &#39;m&#39; or &#39;y&#39;
[f-j]    Dash specifies &quot;range&quot;
[f-j-]   Dash escaped or at start or end means &#39;dash&#39;
[^f-j]   Caret indicates &quot;match any character _except_ these&quot;</code></pre>

<p>The following sequences (except <code>\N</code>) work within or without a character class. The first six are locale aware, all are Unicode aware. See <a href="perllocale.html">perllocale</a> and <a href="perlunicode.html">perlunicode</a> for details.</p>

<pre><code>\d      A digit
\D      A nondigit
\w      A word character
\W      A non-word character
\s      A whitespace character
\S      A non-whitespace character
\h      A horizontal whitespace
\H      A non horizontal whitespace
\N      A non newline (when not followed by &#39;{NAME}&#39;;;
        not valid in a character class; equivalent to [^\n]; it&#39;s
        like &#39;.&#39; without /s modifier)
\v      A vertical whitespace
\V      A non vertical whitespace
\R      A generic newline           (?&gt;\v|\x0D\x0A)

\pP     Match P-named (Unicode) property
\p{...} Match Unicode property with name longer than 1 character
\PP     Match non-P
\P{...} Match lack of Unicode property with name longer than 1 char
\X      Match Unicode extended grapheme cluster</code></pre>

<p>POSIX character classes and their Unicode and Perl equivalents:</p>

<pre><code>           ASCII-         Full-
  POSIX    range          range    backslash
[[:...:]]  \p{...}        \p{...}   sequence    Description

-----------------------------------------------------------------------
alnum   PosixAlnum       XPosixAlnum            &#39;alpha&#39; plus &#39;digit&#39;
alpha   PosixAlpha       XPosixAlpha            Alphabetic characters
ascii   ASCII                                   Any ASCII character
blank   PosixBlank       XPosixBlank   \h       Horizontal whitespace;
                                                  full-range also
                                                  written as
                                                  \p{HorizSpace} (GNU
                                                  extension)
cntrl   PosixCntrl       XPosixCntrl            Control characters
digit   PosixDigit       XPosixDigit   \d       Decimal digits
graph   PosixGraph       XPosixGraph            &#39;alnum&#39; plus &#39;punct&#39;
lower   PosixLower       XPosixLower            Lowercase characters
print   PosixPrint       XPosixPrint            &#39;graph&#39; plus &#39;space&#39;,
                                                  but not any Controls
punct   PosixPunct       XPosixPunct            Punctuation and Symbols
                                                  in ASCII-range; just
                                                  punct outside it
space   PosixSpace       XPosixSpace   \s       Whitespace
upper   PosixUpper       XPosixUpper            Uppercase characters
word    PosixWord        XPosixWord    \w       &#39;alnum&#39; + Unicode marks
                                                   + connectors, like
                                                   &#39;_&#39; (Perl extension)
xdigit  ASCII_Hex_Digit  XPosixDigit            Hexadecimal digit,
                                                   ASCII-range is
                                                   [0-9A-Fa-f]</code></pre>

<p>Also, various synonyms like <code>\p{Alpha}</code> for <code>\p{XPosixAlpha}</code>; all listed in <a href="perluniprops.html#Properties-accessible-through-%5Cp%7B%7D-and-%5CP%7B%7D">&quot;Properties accessible through \p{} and \P{}&quot; in perluniprops</a></p>

<p>Within a character class:</p>

<pre><code class="plaintext">  POSIX      traditional   Unicode
[:digit:]       \d        \p{Digit}
[:^digit:]      \D        \P{Digit}</code></pre>

<h2 id="ANCHORS"><a class="permalink" href="perlreref.html#ANCHORS">#</a>ANCHORS</h2>

<p>All are zero-width assertions.</p>

<pre><code class="plaintext">^  Match string start (or line, if /m is used)
$  Match string end (or line, if /m is used) or before newline
\b{} Match boundary of type specified within the braces
\B{} Match wherever \b{} doesn&#39;t match
\b Match word boundary (between \w and \W)
\B Match except at word boundary (between \w and \w or \W and \W)
\A Match string start (regardless of /m)
\Z Match string end (before optional newline)
\z Match absolute string end
\G Match where previous m//g left off
\K Keep the stuff left of the \K, don&#39;t include it in $&amp;</code></pre>

<h2 id="QUANTIFIERS"><a class="permalink" href="perlreref.html#QUANTIFIERS">#</a>QUANTIFIERS</h2>

<p>Quantifiers are greedy by default and match the <b>longest</b> leftmost.</p>

<pre><code class="plaintext">Maximal Minimal Possessive Allowed range
------- ------- ---------- -------------
{n,m}   {n,m}?  {n,m}+     Must occur at least n times
                           but no more than m times
{n,}    {n,}?   {n,}+      Must occur at least n times
{,n}    {,n}?   {,n}+      Must occur at most n times
{n}     {n}?    {n}+       Must occur exactly n times
*       *?      *+         0 or more times (same as {0,})
+       +?      ++         1 or more times (same as {1,})
?       ??      ?+         0 or 1 time (same as {0,1})</code></pre>

<p>The possessive forms (new in Perl 5.10) prevent backtracking: what gets matched by a pattern with a possessive quantifier will not be backtracked into, even if that causes the whole match to fail.</p>

<h2 id="EXTENDED-CONSTRUCTS"><a class="permalink" href="perlreref.html#EXTENDED-CONSTRUCTS">#</a><a id="EXTENDED"></a>EXTENDED CONSTRUCTS</h2>

<pre><code class="plaintext">(?#text)          A comment
(?:...)           Groups subexpressions without capturing (cluster)
(?pimsx-imsx:...) Enable/disable option (as per m// modifiers)
(?=...)           Zero-width positive lookahead assertion
(*pla:...)        Same, starting in 5.32; experimentally in 5.28
(*positive_lookahead:...) Same, same versions as *pla
(?!...)           Zero-width negative lookahead assertion
(*nla:...)        Same, starting in 5.32; experimentally in 5.28
(*negative_lookahead:...) Same, same versions as *nla
(?&lt;=...)          Zero-width positive lookbehind assertion
(*plb:...)        Same, starting in 5.32; experimentally in 5.28
(*positive_lookbehind:...) Same, same versions as *plb
(?&lt;!...)          Zero-width negative lookbehind assertion
(*nlb:...)        Same, starting in 5.32; experimentally in 5.28
(*negative_lookbehind:...) Same, same versions as *plb
(?&gt;...)           Grab what we can, prohibit backtracking
(*atomic:...)     Same, starting in 5.32; experimentally in 5.28
(?|...)           Branch reset
(?&lt;name&gt;...)      Named capture
(?&#39;name&#39;...)      Named capture
(?P&lt;name&gt;...)     Named capture (python syntax)
(?[...])          Extended bracketed character class
(?{ code })       Embedded code, return value becomes $^R
(??{ code })      Dynamic regex, return value used as regex
(?N)              Recurse into subpattern number N
(?-N), (?+N)      Recurse into Nth previous/next subpattern
(?R), (?0)        Recurse at the beginning of the whole pattern
(?&amp;name)          Recurse into a named subpattern
(?P&gt;name)         Recurse into a named subpattern (python syntax)
(?(cond)yes|no)
(?(cond)yes)      Conditional expression, where &quot;(cond)&quot; can be:
                  (?=pat)   lookahead; also (*pla:pat)
                            (*positive_lookahead:pat)
                  (?!pat)   negative lookahead; also (*nla:pat)
                            (*negative_lookahead:pat)
                  (?&lt;=pat)  lookbehind; also (*plb:pat)
                            (*lookbehind:pat)
                  (?&lt;!pat)  negative lookbehind; also (*nlb:pat)
                            (*negative_lookbehind:pat)
                  (N)       subpattern N has matched something
                  (&lt;name&gt;)  named subpattern has matched something
                  (&#39;name&#39;)  named subpattern has matched something
                  (?{code}) code condition
                  (R)       true if recursing
                  (RN)      true if recursing into Nth subpattern
                  (R&amp;name)  true if recursing into named subpattern
                  (DEFINE)  always false, no no-pattern allowed</code></pre>

<h2 id="VARIABLES"><a class="permalink" href="perlreref.html#VARIABLES">#</a>VARIABLES</h2>

<pre><code>$_    Default variable for operators to use

$`    Everything prior to matched string
$&amp;    Entire matched string
$&#39;    Everything after to matched string

${^PREMATCH}   Everything prior to matched string
${^MATCH}      Entire matched string
${^POSTMATCH}  Everything after to matched string</code></pre>

<p>Note to those still using Perl 5.18 or earlier: The use of <code>$`</code>, <code>$&amp;</code> or <code>$&#39;</code> will slow down <b>all</b> regex use within your program. Consult <a href="perlvar.html">perlvar</a> for <code>@-</code> to see equivalent expressions that won&#39;t cause slow down. See also <a href="./Devel::SawAmpersand.html">Devel::SawAmpersand</a>. Starting with Perl 5.10, you can also use the equivalent variables <code>${^PREMATCH}</code>, <code>${^MATCH}</code> and <code>${^POSTMATCH}</code>, but for them to be defined, you have to specify the <code>/p</code> (preserve) modifier on your regular expression. In Perl 5.20, the use of <code>$`</code>, <code>$&amp;</code> and <code>$&#39;</code> makes no speed difference.</p>

<pre><code>$1, $2 ...  hold the Xth captured expr
$+    Last parenthesized pattern match
$^N   Holds the most recently closed capture
$^R   Holds the result of the last (?{...}) expr
@-    Offsets of starts of groups. $-[0] holds start of whole match
@+    Offsets of ends of groups. $+[0] holds end of whole match
%+    Named capture groups
%-    Named capture groups, as array refs</code></pre>

<p>Captured groups are numbered according to their <i>opening</i> paren.</p>

<h2 id="FUNCTIONS"><a class="permalink" href="perlreref.html#FUNCTIONS">#</a>FUNCTIONS</h2>

<pre><code class="plaintext">lc          Lowercase a string
lcfirst     Lowercase first char of a string
uc          Uppercase a string
ucfirst     Titlecase first char of a string
fc          Foldcase a string

pos         Return or set current match position
quotemeta   Quote metacharacters
reset       Reset m?pattern? status
study       Analyze string for optimizing matching

split       Use a regex to split a string into parts</code></pre>

<p>The first five of these are like the escape sequences <code>\L</code>, <code>\l</code>, <code>\U</code>, <code>\u</code>, and <code>\F</code>. For Titlecase, see <a href="perlreref.html#Titlecase">&quot;Titlecase&quot;</a>; For Foldcase, see <a href="perlreref.html#Foldcase">&quot;Foldcase&quot;</a>.</p>

<h2 id="TERMINOLOGY"><a class="permalink" href="perlreref.html#TERMINOLOGY">#</a>TERMINOLOGY</h2>

<h3 id="Titlecase"><a class="permalink" href="perlreref.html#Titlecase">#</a>Titlecase</h3>

<p>Unicode concept which most often is equal to uppercase, but for certain characters like the German &quot;sharp s&quot; there is a difference.</p>

<h3 id="Foldcase"><a class="permalink" href="perlreref.html#Foldcase">#</a>Foldcase</h3>

<p>Unicode form that is useful when comparing strings regardless of case, as certain characters have complex one-to-many case mappings. Primarily a variant of lowercase.</p>

<h1 id="AUTHOR"><a class="permalink" href="perlreref.html#AUTHOR">#</a>AUTHOR</h1>

<p>Iain Truskett. Updated by the Perl 5 Porters.</p>

<p>This document may be distributed under the same terms as Perl itself.</p>

<h1 id="SEE-ALSO"><a class="permalink" href="perlreref.html#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1>

<ul>

<li><p><a href="perlretut.html">perlretut</a> for a tutorial on regular expressions.</p>

</li>
<li><p><a href="perlrequick.html">perlrequick</a> for a rapid tutorial.</p>

</li>
<li><p><a href="perlre.html">perlre</a> for more details.</p>

</li>
<li><p><a href="perlvar.html">perlvar</a> for details on the variables.</p>

</li>
<li><p><a href="perlop.html">perlop</a> for details on the operators.</p>

</li>
<li><p><a href="perlfunc.html">perlfunc</a> for details on the functions.</p>

</li>
<li><p><a href="perlfaq6.html">perlfaq6</a> for FAQs on regular expressions.</p>

</li>
<li><p><a href="perlrebackslash.html">perlrebackslash</a> for a reference on backslash sequences.</p>

</li>
<li><p><a href="perlrecharclass.html">perlrecharclass</a> for a reference on character classes.</p>

</li>
<li><p>The <a href="re.html">re</a> module to alter behaviour and aid debugging.</p>

</li>
<li><p><a href="perldebug.html#Debugging-Regular-Expressions">&quot;Debugging Regular Expressions&quot; in perldebug</a></p>

</li>
<li><p><a href="perluniintro.html">perluniintro</a>, <a href="perlunicode.html">perlunicode</a>, <a href="charnames.html">charnames</a> and <a href="perllocale.html">perllocale</a> for details on regexes and internationalisation.</p>

</li>
<li><p><i>Mastering Regular Expressions</i> by Jeffrey Friedl (<a href="http://oreilly.com/catalog/9780596528126/">http://oreilly.com/catalog/9780596528126/</a>) for a thorough grounding and reference on the topic.</p>

</li>
</ul>

<h1 id="THANKS"><a class="permalink" href="perlreref.html#THANKS">#</a>THANKS</h1>

<p>David P.C. Wollmann, Richard Soderberg, Sean M. Burke, Tom Christiansen, Jim Cromie, and Jeffrey Goff for useful advice.</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
